package zy1219.zy4;

import org.apache.commons.beanutils.BeanUtils;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.lang.reflect.Constructor;
import java.util.List;

public class demo {
    public static void main(String[] args) throws Exception {
        SAXReader reader = new SAXReader();
        Document read = reader.read("D:\\ideadashuju12\\liu_ya_kai\\src\\zy1219\\zy4\\Car.xml");
        Element root = read.getRootElement();
        List<Element> list = root.elements();
        for (Element e : list) {
            Class<?> aClass = Class.forName(e.attributeValue("className"));
            Constructor<?> c = aClass.getDeclaredConstructor();
            c.setAccessible(true);
            Object o = c.newInstance();
            List<Element> list1 = e.elements();
            for (Element e1 : list1) {
                BeanUtils.setProperty(o,e1.attributeValue("name"),e1.attributeValue("value"));

            }
            System.out.println(o);

        }

    }
}
